package ${packageName}.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.*;
import org.springframework.jdbc.support.GeneratedKeyHolder;
//import org.springframework.stereotype.Repository;

import ${packageName}.domain.*;
import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * Generator by JdbcGenerator
 */
//@Repository
public class ${className}Dao extends  AbstractJDBCDao<${className}>{
     protected static String TABLE_NAME="${tableName}";
     protected static String PRIMARY_KEY="${pkColumn}";
     protected static final String COUNT_ALL = "select count(*) from "+TABLE_NAME;
     protected static final String INSERT_ALL = "${sql_insertAll}";
     protected static final String UPDATE_ALL = "${sql_updateAll}";
     public static RowMapper<${className}> mainRowMapper =new RowMapper<${className}>(){
        @Override
        public ${className} mapRow(ResultSet resultSet, int i) throws SQLException {
            ${className} bean=new ${className}();
<%for (landyer.tools.jdbcGenerator.ColumnBean cb : cbs) {%>
            bean.${cb.getSetterName()}(resultSet.${cb.getResultSetGetterName()}("${cb.getName()}"));<%}%>
            return bean;
        }
    };
    //@Autowired
    //public ${className}Dao(DataSource dataSource){
        //setDataSource(dataSource);
    //}
    @Override
    public MapSqlParameterSource getSqlParams( ${className} bean){
        MapSqlParameterSource params = new MapSqlParameterSource();
<%for (landyer.tools.jdbcGenerator.ColumnBean cb : cbs) {%>
        params.addValue("${cb.getAdjustName()}",bean.${cb.getGetterName()}());<%}%>
        return params;
    }

    @Override
    protected String getSqlInsertAll() {
        return INSERT_ALL;
    }

    @Override
    protected void setPrimaryKey(${className} bean, int pk) {
        bean.${pkSetter}(pk);
    }

    @Override
    protected String getSqlCountAll() {
        return COUNT_ALL;
    }

    @Override
    protected RowMapper<${className}> getMainRowMapper() {
        return mainRowMapper;
    }

    @Override
    protected String getTableName() {
        return TABLE_NAME;
    }

    @Override
    protected String getPrimaryKey() {
        return PRIMARY_KEY;
    }

    @Override
    protected String getSqlUpdateAll() {
        return UPDATE_ALL;
    }
}